package cn.yunhe.biz.temp;

import cn.yunhe.biz.Refrigerator;
import cn.yunhe.exception.OutOfStockException;
import cn.yunhe.model.Customer;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class RefrigeratorImpl1 implements Refrigerator {
    private int quantity=5;
    private int maxCount=1;

    private Map<String,Customer> customerMap=new HashMap<>();

    @Override
    public void saleRefrigerator(Customer customer,int count) throws OutOfStockException {

        Set<Map.Entry<String,Customer>>entrySet2Customer =customerMap.entrySet();
        Iterator<Map.Entry<String,Customer>> iterator= entrySet2Customer.iterator();
        while (iterator.hasNext()){
           Map.Entry<String,Customer> customerEntry= iterator.next();
            System.out.println(customerEntry.getKey()+"==="+customerEntry.getValue());
            if (customer.getName().equals(customerEntry.getKey())&&customer==customerEntry.getValue()){
                break;
            }else {  
                customerMap.put(customer.getName(),customer);
                if (count>maxCount){
                    throw  new OutOfStockException(" 实际购买 "+count+" 台,超出限购总数量: "+maxCount+" 台,无法购买.");
                }
                System.out.println("当前幸运顾客成功 购买特价电冰箱："+count+" 台 ,未超过限购总数量:"+maxCount+" 台.");
            }
        }



    }
}
